const { DataTypes } = require('sequelize');
const sequelize = require('../config/db');
const Author = require('./Author');

const Novel = sequelize.define('Novel', {
  novel_id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true
  },
  novel_name: {
    type: DataTypes.STRING,
    allowNull: false
  },
  author_id: {
    type: DataTypes.UUID,
    allowNull: false
  },
  category: {
    type: DataTypes.STRING,
    allowNull: false
  },
  review: {
    type: DataTypes.TEXT
  },
  status: {
    type: DataTypes.STRING,
    allowNull: false
  },
  chapter_count: {
    type: DataTypes.INTEGER,
    allowNull: false
  },
  page_count: {
    type: DataTypes.INTEGER,
    allowNull: false
  },
  vote_count: {
    type: DataTypes.INTEGER,
    allowNull: false
  },
  content: {
    type: DataTypes.TEXT('long')
  }
}, {
  tableName: 'novel',
  timestamps: true,
  createdAt: 'create_at',
  updatedAt: 'update_at'
});

Novel.belongsTo(Author, { foreignKey: 'author_id', targetKey: 'author_id' });

module.exports = Novel;